import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout/index.vue'
import Login from '@/views/login/index.vue'
// 为什么要用路由懒加载？当需要组件时再加载

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/index.vue'),
        meta: { name1: '用户管理', name2: '用户列表' },
      },
      {
        path: 'user/create',
        component: () => import('@/views/user/create.vue'),
        meta: { name1: '用户管理', name2: '用户创建' },
      },
      {
        path: 'role',
        component: () => import('@/views/role/index.vue'),
        meta: { name1: '角色管理', name2: '角色列表' },
      },
      {
        path: 'role/create',
        component: () => import('@/views/role/create.vue'),
        meta: { name1: '角色管理', name2: '角色创建' },
      },
      {
        path: 'auth',
        component: () => import('@/views/auth/index.vue'),
        meta: { name1: '权限管理', name2: '权限列表' },
      },
      {
        path: 'auth/create',
        component: () => import('@/views/auth/create.vue'),
        meta: { name1: '权限管理', name2: '权限创建' },
      },
      {
        path: 'analysis',
        component: () => import('@/views/index/analysis.vue'),
        meta: { name1: '后台首页', name2: '数据分析' },
      },
    ],
  },
  {
    path: '/login',
    component: Login,
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
